//package com.matt.components.MQ;
//
//import com.aliyun.openservices.ons.api.Consumer;
//import com.aliyun.openservices.ons.api.Producer;
//import com.aliyun.openservices.ons.api.PropertyKeyConst;
//import com.aliyun.openservices.ons.api.bean.ConsumerBean;
//import com.aliyun.openservices.ons.api.bean.ProducerBean;
//import com.aliyun.openservices.ons.api.bean.Subscription;
//import com.matt.commons.utils.ModelUtil;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//import java.util.Properties;
//
//import static com.matt.commons.constant.MQConstant.CRM_TAG.SCHEDULER_DAILY;
//import static com.matt.commons.constant.MQConstant.TOPIC.BASE;
//
//
///**
// * *******************************
// * Created by Ron.
// * form com.matt
// * on 2018/10/24
// * *******************************
// */
//@Configuration
//@Slf4j
//public class MQConfig {
//
//    @Autowired
//    private NormalMessageListener normalMessageListener;
//
//    @Value("${spring.profiles.active}")
//    private String env;
//
//    @Value("${aliyun.access.key.id}")
//    private String ALIYUN_ACCESS_KEY;
//
//    @Value("${aliyun.access.key.secret}")
//    private String ALIYUN_SECRET_KEY;
//
//    @Value("${aliyun.mq.http.addr}")
//    private String ALIYUN_MQ_NAMESRV_ADDR;
//
//    private Properties mqProperties(){
//        Properties properties = new Properties();
//        properties.setProperty(PropertyKeyConst.AccessKey, ALIYUN_ACCESS_KEY);
//        properties.setProperty(PropertyKeyConst.SecretKey, ALIYUN_SECRET_KEY);
//        properties.setProperty(PropertyKeyConst.NAMESRV_ADDR, ALIYUN_MQ_NAMESRV_ADDR);
//        return properties;
//    }
//
//
//    @Bean(initMethod = "start", destroyMethod = "shutdown")
//    public Producer producer() {
//        ProducerBean producerBean = new ProducerBean();
//        Properties properties = mqProperties();
////        properties.put("ProducerId", "PID_CRM");
//        properties.put(PropertyKeyConst.GROUP_ID, String.format("GID_PID_CRM_%s", env));
//        producerBean.setProperties(properties);
//        return producerBean;
//    }
//
//
//    @Bean(initMethod = "start", destroyMethod = "shutdown")
//    public Consumer consumer() {
//        ConsumerBean consumerBean = new ConsumerBean();
//        Properties properties = mqProperties();
////        properties.put("ConsumerId", String.format("CID_CRM_%s", env));
//        properties.put(PropertyKeyConst.GROUP_ID,String.format("GID_CID_CRM_%s", env));
//        properties.put(PropertyKeyConst.ConsumeThreadNums, 50);
//        consumerBean.setProperties(properties);
//        String topic = String.format(BASE.codeOf(), env);
//        String tagExpression = SCHEDULER_DAILY.codeOf();
//        Subscription subscription = new Subscription();
//        subscription.setTopic(topic);
//        subscription.setExpression(tagExpression);
//        consumerBean.setSubscriptionTable(ModelUtil.mapOf(subscription, normalMessageListener));
////        consumerLocal.setStatus("running");
////        consumerLocalService.update(consumerLocal);
//        return consumerBean;
//    }
//
//}
